/**
 * Created by Administrator on 2017/1/20.
 */
var supplier_token;
$.ajax({
    type:'GET',
    url:'http://192.168.1.72:8098/api/cft/admin/get/token',
    contentType:'application/json; charset=gbk',
    data:'',
    dataType:'json',
    success:function (res) {
        supplier_token = res.data;
        console.log(supplier_token);
    },
    error:function (res) {
        layer.msg('登陆失败');

    }
});
$('.save').click(function () {
    var supplier_phone =$('#supplier-phone').val();//登录手机号
    var supplier_name =$('#supplier-name').val();//商家名称
    var supplier_telephone = $('#supplier-telephone').val();//客服电话
    var supplier_address =$('#supplier-address').val();//地址
    var supplier_latlng = $('#supplier-latlng').val();//商家坐标
    var supplier_test =$('#supplier-test').val();//经营种类

    var arr = $('#supplier-latlng').val().split(',');//分割经纬度
    var lat = arr[0];//纬度
    var lng = arr[1];//经度

    if(supplier_phone =='' || supplier_phone == null || supplier_phone == undefined){
        layer.msg('登录手机号不能为空')
    }else
    if(supplier_name =='' || supplier_name == null || supplier_name == undefined){
        layer.msg('供应商名称不能为空')
    }else
    if(supplier_telephone =='' || supplier_telephone == null || supplier_telephone == undefined){
        layer.msg('客服电话不能为空')
    }else
    if(supplier_address =='' || supplier_address == null || supplier_address == undefined){
        layer.msg('供应商地址不能为空')
    }else
    if(supplier_latlng =='' || supplier_latlng == null || supplier_latlng == undefined){
        layer.msg('供应商坐标不能为空')
    }else
    if(supplier_test =='' || supplier_test == null || supplier_test == undefined){
        layer.msg('经营种类不能为空')
    }else{
        alert(supplier_token);
        console.log(supplier_token);
        $.ajax({
            type:'POST',
            url:'http://192.168.1.72:8098/api/cft/admin/create/supply/shop',
            contentType:'application/json',
            data:JSON.stringify({'token':supplier_token,'name':supplier_name,'ownerMobile':supplier_phone,'address':supplier_address,'description':supplier_test,'lat':lat,'lgt':lng,'telephone':supplier_telephone}),
            dataType:'json',
            success:function (res) {
                layer.msg(res.message);
                $('.indexlist').show();
                $('.newtankuang').hide();
            },
            error:function (res) {
                layer.msg('登陆失败');

            }
        })
    }
});